<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <div th:include="template::commonlink"></div>


    <link rel="stylesheet" type="text/css" href="/css/index.css"/>

    <link rel="stylesheet" href="/plugins/dropload/dropload.css">
    <script src="/plugins/dropload/dropload.min.js"></script>
</head>
<body>
<div th:include="template::header"></div>

<div th:include="template::catalog"></div>
<style>
    .data-content .content { /*强制文本在一行内显示*/
        /*white-space:nowrap;*/
        width: 90% !important;
        /*溢出内容为隐藏*/
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
        /*-moz-binding:url('ellipsis.xml#ellipsis');*/
        padding: 20px;
        margin: 10px 5px;
    }

    .article-item {
        margin-top: 20px;
    }

    .article-item .content {
        line-height: 20px;
        max-height: 200px;
    }

    .article-item .content img {
        height: 100px;
    }

    .article-item .content {
        /*溢出内容为隐藏*/
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
    }

    .content p {
        margin-bottom: 20px !important;
    }

    .data-content h1 {
        color: #29B4F0;
        text-decoration: none;
        font-size: 30px;
    }

    .node-header {
        font-size: 15px;
        color: #ccc;
    }

</style>

<div class="d-flex flex-row" style="background-color: #eeeeee">
    <div style="flex:7; width:70%; ">
        <div id="articles" class="d-flex p-3 m-3 bg-light">

            <div class="data-content" style="padding:0 10px; margin-top:-20px;">
                <div v-for="article in articles" class="article-item card p-2">
                    <h1>{{article.article_title}}</h1>
                    <div class="d-flex node-header">
                        <div>
                            <span>作者：{{article.author.te_name}}</span>&nbsp;&nbsp;
                            <span>日期：{{article.releaseTime}}</span>&nbsp;&nbsp;
                            <span class="icon"> &#xe662; {{article.article_zan}}</span>&nbsp;&nbsp;
                            <span class="icon"> &#xe71b; {{article.article_read_count}}</span>
                        </div>
                    </div>

                    <div class="card-body">
                        <div class="content" v-html="article.article_content"></div>
                        <div style="height: 20px;"></div>

                        <a v-bind:href="'/article/detail?id='+article.article_id" class="card-link">阅读全文</a>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <div th:include="template::navlink"></div>

</div>


<div th:include="template::footer"></div>

<script>
    var articleVue = new Vue({
        el: '.data-content',
        data: {
            articles: [],
        }
    })
    // 页数
    var pageIndex = 0;
    // 每页展示5个
    var size = 3;
    // dropload
    $('.data-content').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh" style="font-size:24px;color: #000;">精品文章</div>',
            // domLoad : '<div class="dropload-load">○加载中...</div>',
            domNoData: '<div class="dropload-noData"></div>'
        },
        loadDownFn: function (me) {
            pageIndex++;
            // 拼接HTML
            var result = '';
            $.ajax({
                type: 'POST',
                url: base + '/getArticles',
                data: {pageIndex: pageIndex, pageSize: size},
                success: function (data) {
                    // data = JSON.parse(data)
                    var arrLen = data.length;
                    if (arrLen > 0) {
                        for (var i = 0; i < arrLen; i++) {
                            articleVue.articles.push(data[i])
                        }
                        // 如果没有数据
                    } else {
                        // 锁定
                        me.lock();
                        // 无数据
                        me.noData();
                    }
                    // 为了测试，延迟1秒加载
                    setTimeout(function () {
                        // 插入数据到页面，放到最后面
                        $('.data-content').append(result);
                        // 每次数据插入，必须重置
                        me.resetload();
                    }, 1000);
                },
                error: function (xhr, type) {
                    alert('Ajax error!');
                    // 即使加载出错，也得重置
                    me.resetload();
                }
            });
        }
    });
</script>
</body>
</html>